{% macro articles(_articles) %}
    {% for article in _articles %}
    {% set article_levels = article.level.split('.') %}
    {% set page_levels = page.level.split('.') %}
    {% set article_level_length = article_levels | length %}
    {% set page_level_length = page_levels | length %}
    {% set score = 0 %}
    {% if page_level_length > article_level_length %}
        {% for i in range(article_level_length) %}
            {% if article_levels[i] != page_levels[i] %}
                {% set score = score + article_level_length - i %}
            {% endif %}
        {% endfor %}
    {% else %}
        {% for i in range(page_level_length) %}
            {% if article_levels[i] != page_levels[i] %}
                {% set score = score + page_level_length - i %}
            {% endif %}
        {% endfor %}
        {% set score = score + article_level_length - page_level_length %}
    {% endif %}
    {% if article_level_length < 3 and score > 1 %}
        {% set score = 1 %}
    {% endif %}
    {% if score < 2 %}
        <li class="chapter {% if article.path == file.path and not article.anchor %}active{% endif %}" data-level="{{ article.level }}" {% if article.path %}data-path="{{ article.path|resolveFile }}"{% endif %}>
            {% if article.path %}
                <a href="{{ article.path|resolveFile }}{{ article.anchor }}">
            {% elif article.url %}
                <a target="_blank" href="{{ article.url }}">
            {% else %}
                <span>
            {% endif %}
                    {% if article.level != "0" and config.pluginsConfig['theme-default'].showLevel %}
                        <b>{{ article.level }}.</b>
                    {% endif %}
                    {{ article.title }}
            {% if article.path  or article.url %}
                </a>
            {% else %}
                </span>
            {% endif %}
            {% if article.articles.length > 0 %}
            <ul class="articles">
                {% if score < 1 %}
                {{ articles(article.articles, file, config) }}
                {% endif %}
            </ul>
            {% endif %}
        </li>
    {% endif %}
    {% endfor %}
{% endmacro %}

<ul class="summary">
    {% set _divider = false %}
    {% if config.links.sidebar  %}
    {% for linkTitle, link in config.links.sidebar  %}
        {% set _divider = true %}
        <li>
            <a href="{{ link }}" target="_blank" class="custom-link">{{ linkTitle }}</a>
        </li>
    {% endfor %}
    {% endif %}

    {% if _divider %}
    <li class="divider"></li>
    {% endif %}

    {% for part in summary.parts %}
        {% if part.title %}
        <li class="header">{{ part.title }}</li>
        {% elif not loop.first %}
        <li class="divider"></li>
        {% endif %}
        {{ articles(part.articles, file, config) }}
    {% endfor %}

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            {{ "GITBOOK_LINK"|t }}
        </a>
    </li>
</ul>
